package com.oocl.query.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.oocl.query.pojo.Infomation;
import com.oocl.query.service.InformationService;
import com.oocl.query.service.impl.InfoManagerFactory;
import com.oocl.query.util.JsonObjectConvertor;

/**
 * Servlet implementation class FindListServlet
 */
public class InfomationServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private InformationService service;
    public InfomationServlet() {
    	service = InfoManagerFactory.getInstance();
    }
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		String queryparams = request.getParameter("queryparams");
		String jsonStr = "";
		if("".equals(queryparams)){
			jsonStr = "";
			response.getWriter().write("");
		}else{
			List<Infomation> queryList = service.findByQuery(queryparams);
			jsonStr = JsonObjectConvertor.wrapToJsonFromList(queryList);
			response.getWriter().write(jsonStr);
		}
	}

}
